home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_NewMenu.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  4KB  |  191 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. **
  6. **  :ts=4
  7. */
  8.  
  9. #include "gtlayout_global.h"
  10.  
  11. #ifdef DO_MENUS
  12.  
  13.     /* LTP_NewMenu():
  14.      *
  15.      *    Create a new menu, based on the Screen and Font given.
  16.      */
  17.  
  18. RootMenu * __regargs
  19. LTP_NewMenu(struct Screen *Screen,struct TextAttr *TextAttr,struct Image *AmigaGlyph,struct Image *CheckGlyph,LONG *Error)
  20. {
  21.     if(Screen)
  22.     {
  23.         APTR Pool;
  24.  
  25.             // Start cleanly
  26.  
  27.         *Error = 0;
  28.  
  29.             // Wrap all the allocations into a pool
  30.  
  31.         if(Pool = AsmCreatePool(MEMF_ANY | MEMF_PUBLIC | MEMF_CLEAR,1024,1024,SysBase))
  32.         {
  33.             struct RootMenu *Root;
  34.  
  35.                 // Create the root
  36.  
  37.             if(Root = (struct RootMenu *)AsmAllocPooled(Pool,sizeof(struct RootMenu),SysBase))
  38.             {
  39.                 Root -> Pool = Pool;
  40.  
  41.                 if(TextAttr)
  42.                     Root -> TextAttr = TextAttr;
  43.                 else
  44.                     Root -> TextAttr = Screen -> Font;
  45.  
  46.                     // Open the menu font
  47.  
  48.                 if(Root -> Font = OpenFont(Root -> TextAttr))
  49.                 {
  50.                         // Get the drawing information
  51.  
  52.                     if(Root -> DrawInfo = GetScreenDrawInfo(Screen))
  53.                     {
  54.                             // Fill in the dummy rastport
  55.  
  56.                         InitRastPort(&Root -> RPort);
  57.  
  58.                         Root -> RPort . BitMap = Screen -> RastPort . BitMap;
  59.  
  60.                         SetFont(&Root -> RPort,Root -> Font);
  61.  
  62.                                 // Get the text rendering pen
  63.  
  64.                         if(Root -> DrawInfo -> dri_Version < 2)
  65.                             Root -> TextPen = Root -> DrawInfo -> dri_Pens[DETAILPEN];
  66.                         else
  67.                             Root -> TextPen = Root -> DrawInfo -> dri_Pens[BARDETAILPEN];
  68.  
  69.                                 // Something to remember
  70.  
  71.                         Root -> Screen = Screen;
  72.  
  73.                             // Let's hope it won't grow in the future
  74.  
  75.                         CopyMem(Root -> TextAttr,&Root -> BoldAttr,sizeof(struct TTextAttr));
  76.  
  77.                             // Make it boldface
  78.  
  79.                         Root -> BoldAttr . tta_Style |= FSF_BOLD;
  80.  
  81.                             // Initialize the lists
  82.  
  83.                         NewList((struct List *)&Root -> MenuList);
  84.                         NewList((struct List *)&Root -> ItemList);
  85.  
  86.                             // Get the glyph widths
  87.  
  88.                         if(CheckGlyph)
  89.                         {
  90.                             GetAttr(IA_Width,    CheckGlyph,&Root -> CheckWidth);
  91.                             GetAttr(IA_Height,    CheckGlyph,&Root -> CheckHeight);
  92.                         }
  93.                         else
  94.                         {
  95.                                 // No glyph is provided, use the default values
  96.  
  97.                             if(V39)
  98.                             {
  99.                                 struct Image *Glyph;
  100.  
  101.                                 if(Glyph = NewObject(NULL,SYSICLASS,
  102.                                     SYSIA_DrawInfo,         Root -> DrawInfo,
  103.                                     SYSIA_Which,            MENUCHECK,
  104.                                     SYSIA_ReferenceFont,    Root -> Font,
  105.                                 TAG_DONE))
  106.                                 {
  107.                                     GetAttr(IA_Width,    Glyph,&Root -> CheckWidth);
  108.                                     GetAttr(IA_Height,    Glyph,&Root -> CheckHeight);
  109.  
  110.                                     DisposeObject(Glyph);
  111.                                 }
  112.                             }
  113.  
  114.                             if(!Root -> CheckWidth)
  115.                                 Root -> CheckWidth = 15;
  116.  
  117.                             if(!Root -> CheckHeight)
  118.                                 Root -> CheckHeight    = 8;
  119.                         }
  120.  
  121.                         if(AmigaGlyph)
  122.                         {
  123.                             GetAttr(IA_Width,    AmigaGlyph,&Root -> AmigaWidth);
  124.                             GetAttr(IA_Height,    AmigaGlyph,&Root -> AmigaHeight);
  125.                         }
  126.                         else
  127.                         {
  128.                                 // No glyph is provided, use the default values
  129.  
  130.                             if(V39)
  131.                             {
  132.                                 struct Image *Glyph;
  133.  
  134.                                 if(Glyph = NewObject(NULL,SYSICLASS,
  135.                                     SYSIA_DrawInfo,         Root -> DrawInfo,
  136.                                     SYSIA_Which,            AMIGAKEY,
  137.                                     SYSIA_ReferenceFont,    Root -> Font,
  138.                                 TAG_DONE))
  139.                                 {
  140.                                     GetAttr(IA_Width,    Glyph,&Root -> AmigaWidth);
  141.                                     GetAttr(IA_Height,    Glyph,&Root -> AmigaHeight);
  142.  
  143.                                     DisposeObject(Glyph);
  144.                                 }
  145.                             }
  146.  
  147.                             if(!Root -> AmigaWidth)
  148.                                 Root -> AmigaWidth = 23;
  149.  
  150.                             if(!Root -> AmigaHeight)
  151.                                 Root -> AmigaHeight = 8;
  152.                         }
  153.  
  154.                             // Establish default menu item height
  155.  
  156.                         Root -> ItemHeight = Root -> RPort . TxHeight;
  157.  
  158.                         if(Root -> CheckHeight > Root -> ItemHeight)
  159.                             Root -> ItemHeight = Root -> CheckHeight;
  160.  
  161.                         if(Root -> AmigaHeight > Root -> ItemHeight)
  162.                             Root -> ItemHeight = Root -> AmigaHeight;
  163.  
  164.                         Root -> ItemHeight += 2;
  165.  
  166.                         return(Root);
  167.                     }
  168.                     else
  169.                         *Error = ERROR_NO_FREE_STORE;
  170.  
  171.                     CloseFont(Root -> Font);
  172.                 }
  173.                 else
  174.                     *Error = ERROR_OBJECT_NOT_FOUND;
  175.             }
  176.             else
  177.                 *Error = ERROR_NO_FREE_STORE;
  178.  
  179.             AsmDeletePool(Pool,SysBase);
  180.         }
  181.         else
  182.             *Error = ERROR_NO_FREE_STORE;
  183.     }
  184.     else
  185.         *Error = ERROR_REQUIRED_ARG_MISSING;
  186.  
  187.     return(NULL);
  188. }
  189.  
  190. #endif    /* DO_MENUS */
  191.